import popuplib2

from wcs.libs.constants import *
from wcs.libs.config import *

__all__ = ["mainPopup"]

def mainMenuSelect(args):
    """
    Executed when an option from the main menu has been selected.
    
    @param dict args A list of arguments that pouplib2 automatically builds
    """
    from wcs.libs.items.popups import buildItemPopup
    from wcs.libs.players import players
    from wcs.libs.races import races
    from wcs.libs.races.groups import raceGroups
    from wcs.libs.messages import messages
    
    userid = args["userid"]
    choice = args["choice"]
    
    if choice == 1:
        buildItemPopup().send(userid)
    
    elif choice == 2:
        #TODO: Add reset skill functionality
        es.tell(userid, "#green", "This functionality is on my TODO list")
        return args["popup"]
    
    elif choice == 3:
        player = players[userid]
        if player is not None:
            races[player.currentRace].skillsPopup.send(userid)
        
    elif choice == 4:
        raceGroups.popup.send(userid)
        
    elif choice == 5:
        #TODO: Add Player stat info functionality
        es.tell(userid, '#green', "This functionality is on my TODO list")
        return args["popup"]
    
    elif choice == 6:
        #TODO: Add TOP10 functionality
        es.tell(userid, '#green', "This functionality is on my TODO list")
        return args["popup"]
        
    elif choice == 7:
        wcsPlayer = players[userid]
        race = wcsPlayer.currentRace
        raceObject = wcsPlayer[race]
        level = raceObject.level
        xp = raceObject.xp
        xpNeeded = int(startXP) + (level - 1) * int(xpIncrement)
        tokens = {}
        tokens["level"] = level
        tokens["currentxp"] = xp
        tokens["race"] = race
        tokens["neededxp"] = xpNeeded
        messages.send(userid, "player race summary", tokens)

mainPopup = popuplib2.Popup()
mainPopup.append("- %s Menu -" % info.name)
mainPopup.append("Version: %s" % info.version)
mainPopup.append("-" * 15)
mainPopup.append("->1. Shop Menu")
mainPopup.append("-" * 15)
mainPopup.append("->2. Reset Skills")
mainPopup.append("->3. Spend Skills")
mainPopup.append("-" * 15)
mainPopup.append("->4. Change Race")
mainPopup.append("-" * 15)
mainPopup.append("->5. Player Information")
mainPopup.append("->6. Top 10")
mainPopup.append("->7. Your Rank")
mainPopup.append("-" * 15)
mainPopup.append("0. Cancel")
mainPopup.menuselect = mainMenuSelect